#include <set>
#include <iostream>
#include <string>
#include <algorithm>

typedef std::set<std::string> ListStrings;
int main()
{
	std::cout<<"Enter the number of names in first collection"<<'\n';
	int num = 0;
	std::cin>>num;
	std::cout<<"Enter the names"<<'\n';
	std::string name;
	ListStrings first_col;
		for(int i =0; i<num; i++)
	{
		std::cin>>name;
		first_col.insert(name);
	}
	std::cout<<"Enter the number of names in second collection"<<'\n';
	std::cin>>num;
	std::cout<<"Enter the names"<<'\n';
	ListStrings second_col;
	for(int i=0; i<num; i++)
	{
		std::cin>>name;
		second_col.insert(name);
	}
	std::cout<<"Result of comparing: \n";
	set_intersection(first_col.begin(),first_col.end(),second_col.begin(),
		second_col.end(),std::ostream_iterator<std::string>(std::cout, "\t"));
	std::cout<<std::endl;

	return 0;

}
